﻿using System;
using Cuce.ReportingServices.SSRSWS;
using Cuce.ReportingServices.UnitTests.Mock;
using NUnit.Framework;

namespace Cuce.ReportingServices.UnitTests
{

    /// <summary>
    /// 
    /// </summary>
    [TestFixture]
    public class IntergratedTestWrapperTest
    {

        private IntergratedTestWrapper i;
        private const string _validReportServer = "http://melwdscrr01/ReportServer";
        private const string _testReportName = "testreport";

        /// <summary>
        /// Tests the working.
        /// </summary>
        [Test]
        public void TestWorking()
        {
            try
            {

                i = new IntergratedTestWrapper(new ReportingServicesMock()) {ReportServer = _validReportServer};

                ReportResult h = i.TestReport(new ReportName(_testReportName, "/"));
               
                Assert.IsTrue(h == ReportResult.PASS);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(false);
            }

        }

        /// <summary>
        /// Tests the name of if no report.
        /// </summary>
        [Test]
        public void TestIfNoReportName()
        {
            try
            {

                i = new IntergratedTestWrapper(new ReportingServicesMock()) {ReportServer = _validReportServer};
               
                i.TestReport(new ReportName("", "/"));
                
                Assert.IsTrue(false);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
            }

        }

        /// <summary>
        /// Tests if no URL set.
        /// </summary>
        [Test]
        public void TestIfNoUrlSet()
        {
            try
            {

                i = new IntergratedTestWrapper(new ReportingServicesMock());
               
                i.TestReport(new ReportName("test", "/"));
                
                Assert.IsTrue(false);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
            }

        }

        /// <summary>
        /// Tests if parameter null.
        /// </summary>
        [Test]
        public void TestIfParameterNull()
        {
            try
            {

                i = new IntergratedTestWrapper(new ReportingServicesMock()) {ReportServer = _validReportServer};
                
                i.TestReport(new ReportName("test", "/"), null);
                
                Assert.IsTrue(false);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
            }

        }

        ///<summary>
        ///</summary>
        [Test]
        public void TestIfParameterNameNull()
        {
            try
            {

                i = new IntergratedTestWrapper(new ReportingServicesMock()) {ReportServer = _validReportServer};
                
                i.TestReport(null);

                Assert.IsTrue(false);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
            }

        }

        /// <summary>
        /// Tests if RS exception thrown.
        /// </summary>
        [Test]
        public void TestIfRSExceptionThrown()
        {
            try
            {
                i = new IntergratedTestWrapper(new ReportingServicesMock()) {ReportServer = _validReportServer};

                var list = new ParameterValue[1];
                list[0] = new ParameterValue {Name = "Error"};

                ReportResult h = i.TestReport(new ReportName("test", "/"), list);

                Assert.IsTrue(h == ReportResult.FAIL);
            }
            catch (ReportException)
            {
                Assert.IsTrue(true);
            }


        }

        /// <summary>
        /// Tests if RS warnings thrown.
        /// </summary>
        [Test]
        public void TestIfRSWarningsThrown()
        {
            try
            {
                i = new IntergratedTestWrapper(new ReportingServicesMock()) { ReportServer = _validReportServer };

                var list = new ParameterValue[1];
                list[0] = new ParameterValue {Name = "Warning"};

                ReportResult h = i.TestReport(new ReportName("test", "/"), list);

                Assert.IsTrue(h == ReportResult.WARNINGS);
            }
            catch (ReportException e)
            {

                if (e.Warnings.Length > 0)
                {
                    Assert.IsTrue(e.Warnings[0].Message == "Warning");
                }
                else
                    Assert.IsTrue(false);
            }


        }

      
      
    }
}
